let nums = [1,5,4,2,9,9,9]
let k = 3
var maximumSubarraySum = function(nums, k) {
    let map = new Map()
    let sum = 0
    let max = 0
    for(let i=0;i<nums.length;i++){
        if(map.has(nums[i])){
            map.set(nums[i],map.get(nums[i])+1)
        }else{
            map.set(nums[i],1)
        }
        sum += nums[i]
        if(i-k+1<0){
            continue
        }
        if(map.size===k){
            max = Math.max(max,sum)
        }
        let out = nums[i-k+1]
        if(map.get(out)===1){
            map.delete(out)
        }else{
            map.set(out,map.get(out)-1)
        }
        sum -= out
    }
    return max
};
console.log(maximumSubarraySum(nums,k))
